import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_animation_set/animation_set.dart';
import 'package:flutter_animation_set/animator.dart';
import 'package:flutter_app_study/Single/SIngleUserEntity.dart';
import 'package:flutter_app_study/bean/ConditionBean.dart';
import 'package:flutter_app_study/bean/CounterModel.dart';
import 'package:flutter_app_study/cost/Strings.dart';
import 'package:flutter_app_study/utils/ImageUtil.dart';
import 'package:flutter_app_study/view/ConditionWidget.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:logger/logger.dart';
import 'package:provider/provider.dart';

class ShopFragment extends StatefulWidget {
  @override
  _ShopFragmentState createState() => _ShopFragmentState();
}

class _ShopFragmentState extends State<ShopFragment>
    with WidgetsBindingObserver {
  List<ConditionBean> dataList = [];

  @override
  void initState() {
    // TODO: implement initState
    WidgetsBinding.instance.addObserver(this);
    dataList.add(ConditionBean(isCheck: false, id: 1, name: "包到"));
    dataList.add(ConditionBean(isCheck: false, id: 2, name: "自提"));
    dataList.add(ConditionBean(isCheck: true, id: 3, name: "包邮"));
    dataList.add(ConditionBean(isCheck: false, id: 4, name: "到付"));
    dataList.add(ConditionBean(isCheck: false, id: 5, name: "月结"));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 50),
      child: ListView(
        children: <Widget>[
          ConditionWidget(dataList,onSelect: (ConditionBean conditionBean){
            Logger().wtf(conditionBean.name);
          },),
          getTextWidget(),
          getInputWidget(),
          getImageWidget(),
          getButtonWidget(),
        ],
      ),
    );
  }

  @override
  void dispose() {
    // TODO: implement dispose
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
//    resumed - 应用程序可见并响应用户输入。这是来自Android的onResume
//    inactive - 应用程序处于非活动状态，并且未接收用户输入。此事件在Android上未使用，仅适用于iOS
//    paused - 应用程序当前对用户不可见，不响应用户输入，并在后台运行。这是来自Android的暂停
//    suspending - 该应用程序将暂时中止。这在iOS上未使用
  }
}

Widget getTextWidget() {
  return Row(
    children: <Widget>[
      Expanded(
          flex: 1,
          child: Container(
            child: Text("Text"),
            color: Colors.white,
          )),
      Expanded(
          flex: 2,
          child: Container(
            child: Text("Text"),
            color: Colors.red,
          )),
      Text("Tex31111111111111111111t"),
    ],
  );
}

Widget getImageWidget() {
  return Image.asset(ImageUtil.getImageAsset("1.png"),
      width: 250, height: 250, fit: BoxFit.fill);
}

Widget getButtonWidget() {
  return RaisedButton(
      onPressed: () {
        Fluttertoast.showToast(
            msg: "This is Center Short Toast",
            toastLength: Toast.LENGTH_SHORT,
            gravity: ToastGravity.CENTER,
            timeInSecForIos: 1,
            backgroundColor: Colors.red,
            textColor: Colors.white,
            fontSize: 16.0);
      },
      elevation: 10,
      color: Colors.yellow,
      textColor: Colors.black87,
      disabledColor: Colors.blue,
      focusColor: Colors.red,
      hoverColor: Colors.red,
      highlightColor: Colors.blue,
      splashColor: Colors.red,
      child: Text(Strings.name));
}

Widget makeWave(int before, int after) {
  return AnimatorSet(
    child: Container(
      color: Colors.red,
      width: 5,
      height: 15,
    ),
    animatorSet: [
      Delay(duration: before),
      SY(from: 0.8, to: 1.6, duration: 200, delay: 0, curve: Curves.linear),
      SY(from: 1.6, to: 0.8, duration: 200, delay: 0, curve: Curves.linear),
      Delay(duration: after),
    ],
  );
}

Widget getInputWidget() {
  return TextField(
    controller: TextEditingController(text: "1111111"),
    textAlign: TextAlign.start,
    minLines: 1,
    maxLines: 1,
    maxLength: 5,
    autofocus: false,
    scrollController: ScrollController(),
    cursorColor: Colors.red,
    style: TextStyle(fontWeight: FontWeight.bold, color: Colors.blue),
    inputFormatters: [
      WhitelistingTextInputFormatter.digitsOnly,
      BlacklistingTextInputFormatter.singleLineFormatter
    ],
    decoration: new InputDecoration(hintText: "请输入", icon: Icon(Icons.add)),
  );
}
